package cn.aeolia.utils;

import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * yaml工具类
 * 功能：
 *      1.解析yaml文件为Map<String, Object>
 * @author aeolia
 */
public class YamlUtils {

    public static Map<String,Object> analysisYaml() {
        String path = "application.yaml";
        URL url = YamlUtils.class.getClassLoader().getResource(path);
        if (null != url) {
            Yaml yaml = new Yaml();
            try {
                Map<String,Object> map = yaml.load(new FileInputStream(url.getFile()));
                System.out.println(map);
                return map;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public static void main(String[] args) {
        Map<String, Object> map = analysisYaml();
        for (String key : map.keySet()) {
            Object value = map.get(key);

            System.out.println(value);
        }
    }
}
